﻿import { Component } from '@angular/core';
import { sampleProducts } from './productsForGrid';

@Component({
    templateUrl: 'grid.component.html'
})
export class GridComponent {

    constructor() { }

    public products: any[] = sampleProducts;

    public onExcelExport(e: any): void {
        const rows = e.workbook.sheets[0].rows;

        //align multi header
        rows[0].cells[2].hAlign = 'center';

        //set alternating row color
        let altIdx = 0;
        rows.forEach((row) => {
            if (row.type == 'data') {
                if (altIdx % 2 !== 0) {
                    row.cells.forEach((cell) => {
                        cell.background = "#aabbcc";
                    });
                }
                altIdx++;
            }
        });
    }
}
